class UserSessionsController < ApplicationController

  before_filter :require_no_user, :only => [:new, :create]
  before_filter :require_user, :only => :destroy

  def new
    @user_session = UserSession.new
  end

  def create
    
    @user_session = UserSession.new(params[:user_session])
    if @user_session.save
      if session[:return_to]
        redirect_to(session[:return_to])
      else
        flash[:notice] = "Login successful!"
        redirect_to dashboard_path
      end
    else
      render :action => :new
    end
  end

  def destroy
    current_user_session.destroy
    flash[:notice] = "Logout successful!"
    session[:return_to] = nil
    redirect_to login_path
  end

end
